﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZLDC.Common.Estate;
using System.Data;
using System.Web;
namespace ZLDC.Topo.BLL.Estate
{
    public class lp_Report_Userlist
    {
        public lp_Report_Userlist()
        { }

                                                                public static string GetUserList(string statrday, string endday, string userid, System.Web.UI.HtmlControls.HtmlGenericControl Percentage)
        {
            #region
            StringBuilder sb = new StringBuilder();
            decimal cell1 = 0;            decimal cell2 = 0;            decimal cell3 = 0;            int fk = 0;            if (statrday != "0" && endday != "0")
            {
                string sql = "select sum(lc.Actual_Goal) as Actual_Goal,lc.Other1,Unit,BasisName,sum(SinglePoint) as SinglePoint,userID,sum(lc.Quantity) as Quantity,sum(Actual_Number) as Actual_Number from lp_Configuration lc left join lp_Basis lb on lc.BasisName=lb.Name  where CONVERT(varchar,lc.CreateTime,23)>='" + statrday + "' and CONVERT(varchar,lc.CreateTime,23)<='" + endday + "' and userID=" + userid + " and (lc.Quantity!=0 or lc.Actual_Goal!=0 or lc.Actual_Number!=0) group by BasisName,userID,Unit,lc.Other1 order by lc.Other1 desc";
                DataSet ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    fk++;
                    sb.Append("<table id=\"tb1\" width=\"500px\" cellpadding=\"0\" cellspacing=\"1\" border=\"0\" style='font-size:16px;'>");
                    sb.Append("<caption></caption>");
                    sb.Append("<thead>");
                    sb.Append("<tr>");
                    sb.Append("<th align=\"center\" width=\"80\"  class=\"th\">");
                    sb.Append("工作内容");
                    sb.Append("</th>");
                    sb.Append("<th align=\"center\" width=\"70\"  class=\"th\">");
                    sb.Append("完成量");
                    sb.Append("</th>");
                    sb.Append("<th align=\"center\" width=\"80\"  class=\"th\">");
                    sb.Append("得分");
                    sb.Append("</th>");
                    sb.Append("<th align=\"center\" width=\"70\"  class=\"th\">");
                    sb.Append("要求得分");
                    sb.Append("</th>");

                    sb.Append("</tr>");
                    sb.Append("</thead>");
                    sb.Append("<tbody>");
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        if (ds.Tables[0].Rows[i]["Other1"].ToString() == "1")
                        {
                            sb.Append("<tr style='color:#9B1F07'>");
                        }
                        else
                        {
                            sb.Append("<tr>");
                        }
                        sb.Append("<td class=\"td\">");
                        sb.Append("<div style='cursor:pointer;font-size:16px;' onclick=\"fkqi(" + ds.Tables[0].Rows[i]["userID"].ToString() + ",'" + ds.Tables[0].Rows[i]["BasisName"].ToString() + "')\">" + ds.Tables[0].Rows[i]["BasisName"].ToString());
                        if (ds.Tables[0].Rows[i]["Quantity"].ToString() != "0")
                        {
                            sb.Append(ds.Tables[0].Rows[i]["Quantity"].ToString());
                        }
                        else
                        {
                            sb.Append("(");
                        }
                        sb.Append(ds.Tables[0].Rows[i]["unit"].ToString());
                        if (ds.Tables[0].Rows[i]["Quantity"].ToString() == "0")
                        sb.Append(")");
                        sb.Append(" </div></td>");
                        if (ds.Tables[0].Rows[i]["Other1"].ToString() == "1")
                        {
                            sb.Append("<td class=\"td\" style='color:#48A1EF'>");
                        }
                        else
                        {
                            sb.Append("<td class=\"td\" >");
                        }
                        sb.Append(ds.Tables[0].Rows[i]["Actual_Number"].ToString());
                        cell1 += Convert.ToDecimal(ds.Tables[0].Rows[i]["Actual_Number"].ToString() == "" ? "0" : ds.Tables[0].Rows[i]["Actual_Number"].ToString());
                        sb.Append("</td>");
                        sb.Append("<td class=\"td\"  style='color:#299129'>");
                        sb.Append(ds.Tables[0].Rows[i]["Actual_Goal"].ToString());

                        cell2 += Convert.ToDecimal(ds.Tables[0].Rows[i]["Actual_Goal"].ToString() == "" ? "0" : ds.Tables[0].Rows[i]["Actual_Goal"].ToString());
                        sb.Append("</td>");
                        if (ds.Tables[0].Rows[i]["Other1"].ToString() == "1")
                        {
                            sb.Append("<td class=\"td\"  style='color:#299129'>");
                        }
                        else
                        {
                            sb.Append("<td class=\"td\">");
                        }
                        sb.Append(ds.Tables[0].Rows[i]["SinglePoint"].ToString());

                        cell3 += Convert.ToDecimal(ds.Tables[0].Rows[i]["SinglePoint"].ToString() == "" ? "0" : ds.Tables[0].Rows[i]["SinglePoint"].ToString());
                        sb.Append("</td>");
                        sb.Append("</tr>");
                    }

                }
                if (fk > 0)
                {
                    sb.Append("<tr style='color:red'>");
                    sb.Append("<td>");
                    sb.Append("总计:");
                    sb.Append("</td>");
                    sb.Append("<td>");
                    sb.Append(cell1);
                    sb.Append("</td>");
                    sb.Append("<td>");
                    sb.Append(cell2);
                    sb.Append("</td>");
                    sb.Append("<td>");
                    sb.Append(cell3);
                    sb.Append("</td>");
                    sb.Append("</tr>");
                                        if (cell3 != 0)
                        Percentage.InnerHtml = "今日工作完成率：" + ((cell2 / cell3) * 100).ToString("0.00") + "%";
                                        string sqlreply = "select  Configuration_mainID,Reply,CreateName,CONVERT(varchar,createtime,23) as CreateTime,CONVERT(varchar,txtTime,23)as txtTime from lp_main_Reply where Configuration_mainID in (select id from lp_Configuration_main where userID=" + userid + " and (workDay='" + statrday + "' or  DATEDIFF(dd, CreateTime,'" + statrday + "')=1))  order by createtime desc";
                    ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sqlreply);
                    if (ds.Tables.Count > 0)
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            sb.Append("<tr  style='color:#9B1F07'>");
                            sb.Append("<td class=\"td\" colspan=\"2\">");
                                sb.Append("今日工作意见");
                                sb.Append("</td>");
                                sb.Append("<td class=\"td\" colspan=\"2\">");
                                sb.Append("昨日工作点评");
                                sb.Append("</td>");
                                sb.Append("</tr>");
                                sb.Append("<tr  style='color:#9B1F07'>");
                                sb.Append("<td class=\"td\" colspan=\"2\" >");
                                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                                {
                                    if (ds.Tables[0].Rows[i]["txtTime"].ToString() == DateTime.Now.ToString("yyyy-MM-dd"))
                                    {

                                        sb.Append("<div style='font-size:16px;'>");
                                        sb.Append(ds.Tables[0].Rows[i]["CreateName"].ToString());
                                        sb.Append(":" + ds.Tables[0].Rows[i]["Reply"].ToString());
                                        sb.Append("</div>");
                                    }
                                  

                                }
                                sb.Append("</td>");
                              
                                sb.Append("<td class=\"td\" colspan=\"2\">");
                                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                                {
                                    if (ds.Tables[0].Rows[i]["txtTime"].ToString() != DateTime.Now.ToString("yyyy-MM-dd"))
                                    {

                                        sb.Append("<div  style='font-size:16px;'>");
                                        sb.Append(ds.Tables[0].Rows[i]["CreateName"].ToString());
                                        sb.Append(":" + ds.Tables[0].Rows[i]["Reply"].ToString());
                                        sb.Append("</div>");
                                    }
                                   



                                }
                                sb.Append("</td>");
                                sb.Append("</tr>");
                         
                        }
                    sb.Append("<tr style='color:red'>");
                    sb.Append("<td colspan=\"4\">");
                    sb.Append(ZLDC.Topo.BLL.Estate.lp_myListUrl.returnUrl(userid));
                    sb.Append("</td>");
                    sb.Append("</tr>");
                    sb.Append("</tbody>");
                    sb.Append("</table>");
                }
                else
                {
                    sb.Append("<span style='color:red'>经理未安排工作！</span>");
                }
            }
            return sb.ToString();
            #endregion
        }

        public static void lp_pro_updatelist(string type, string userid, string deptid, string datetime)
        {
            ZLDC.DAL.Estate.lp_Basis.lp_pro_updatelist(type, userid, deptid, datetime);
        }
    }
}
